package pms.userLogin.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import pms.userLogin.form.UserLoginForm;
import pms.userLogin.service.UserLoginService;

/**
 * 标题：用户登录Controller<br>
 * 概述：用户登录Controller<br>
 * 生成时间：2013-5-26 下午9:31:53<br>
 * 作者：李威<br>
 */
@Controller
@RequestMapping("/UserLoginController")
public class UserLoginController {

    @Autowired
    private UserLoginService userLoginService;
    
    /**
     * 描述：用于页面显示
     * @param model 视图
     * @return String
     */
    @RequestMapping(value="/login",method=RequestMethod.GET)
    public String excute(Model model){
        UserLoginForm userLoginForm = new UserLoginForm();
        userLoginForm.setUserId(null);
        userLoginForm.setUserPassword(null);
        userLoginForm.setRemeberMe(null);
        model.addAttribute("userLoginForm",userLoginForm);
        return "/userLogin/userLogin";
    }
    /**
     * 描述：提交userLoginForm表单
     * @param userLoginForm 提交form
     * @return String
     */
    @RequestMapping(value="/login",method=RequestMethod.POST)
    public String excute(@ModelAttribute("UserLoginForm")  UserLoginForm userLoginForm){
        String checkFlag = userLoginService.checkUser(userLoginForm.getUserId(), userLoginForm.getUserPassword());
        if(checkFlag != null){
            return "userLogin.jsp";
        }else{
            return "/userLogin/success";
        }
    }
    
}
